# -*- coding: UTF-8 -*-
# __author__ = 'Sengo'
from settings import BASE_DIR


def read_data(path=None):
    if not path:
        path = BASE_DIR + "/txt/shuttle.d.txt"
    _sum = []
    vertexes = []
    lines = []
    _first_line = 1
    _vertex_line = 0
    with open(path) as f:
        for data in f.readlines():
            data = data.strip('\n')
            # nums for one line
            nums = data.split(" ")
            # read fist line
            if _first_line:
                for re in nums:
                    if re:
                        _sum.append(re)
                _first_line = 0
                continue
            _vertex_line = int(_sum[1])

    # read vertexes and lines
    with open(path) as f:
        i = 1
        for data in f.readlines():
            data = data.strip('\n')
            nums = data.split(" ")
            if i:
                i = 0
                continue
            if _vertex_line:
                _vertex = []
                for re in nums:
                    if re:
                        _vertex.append(float(re))
                vertexes.append(_vertex)
                _vertex_line -= 1
                continue

            # lines
            _line = []
            for re in nums:
                if re:
                    _line.append(int(re)-1)
            lines.append(_line[1:])
    # print _sum
    # print vertexes
    # print lines
    return vertexes, lines


if __name__ == '__main__':
    path = BASE_DIR + "/txt/house.d.txt"
    vertexes, lines = read_data(path)
    print vertexes
